package com.exam.controller;
import com.exam.entity.WrongQuestion;
import com.exam.service.WrongQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
//错题库的增删改查
@RestController
@RequestMapping("/api/wrong-questions")
public class WrongQuestionController {

    @Autowired
    private WrongQuestionService wrongQuestionService;

    @PostMapping
    public WrongQuestion addWrongQuestion(@RequestBody WrongQuestion wrongQuestion) {
        return wrongQuestionService.addWrongQuestion(wrongQuestion);
    }

    @DeleteMapping("/{id}")
    public void deleteWrongQuestion(@PathVariable Long id) {
        wrongQuestionService.deleteWrongQuestion(id);
    }

    @GetMapping("/{id}")
    public WrongQuestion getWrongQuestionById(@PathVariable Long id) {
        return wrongQuestionService.getWrongQuestionById(id);
    }

    @GetMapping("/paged")
    public Page<WrongQuestion> getAllWrongQuestionsPaged(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        Pageable pageable = PageRequest.of(page, size);
        return wrongQuestionService.getAllWrongQuestions(pageable);
    }
}